package com.hpjz.basicofing.web.controller;


import java.util.List;

import javax.annotation.Resource;

import lombok.extern.log4j.Log4j;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hpjz.basicofing.service.ICarService;
import com.hpjz.basicofing.web.vo.CarVO;
import com.hpjz.basicofing.web.vo.RunCarVO;
import com.hpjz.common.ParameterBean;
import com.hpjz.common.ResultBean;
import com.hpjz.common.utils.ConstantDefinition;
import com.hpjz.emrecord.web.vo.EmRecordVO;

@Controller
@RequestMapping("/car")
@Log4j
public class CarController {
	
	/**
	 * 车辆service
	 */
	@Resource
	private ICarService carService;
	
	
	/**
	 * 添加车辆
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/insertCar",method = RequestMethod.POST)
	public @ResponseBody ResultBean insertCar(@RequestBody ParameterBean pb){
		CarVO objMap = (CarVO) pb.getParameter(CarVO.class);
		ResultBean result = new ResultBean();
		 try {
			 boolean isRepeat =  this.carService.insertCar(objMap);
			 if (isRepeat) {
				result.setStatus(ConstantDefinition.SYETEM_DATA_REPEAT);
			  }else{
			  result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
			 }
		} catch (Exception e) {
			 log.error("添加车辆信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}

	/**
	 * 查询车辆信息
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/findCar",method = RequestMethod.POST)
	public @ResponseBody ResultBean findCar(@RequestBody ParameterBean pb){
		CarVO objMap = (CarVO) pb.getParameter(CarVO.class);
		ResultBean result = new ResultBean();
		 try {
			 CarVO uvo =  this.carService.findCar(objMap);
			 result.setResult(uvo);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("查询车辆信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	/**
	 * 修改车辆信息
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/updateCar",method = RequestMethod.POST)
	public @ResponseBody ResultBean updateCar(@RequestBody ParameterBean pb){
		CarVO objMap = (CarVO) pb.getParameter(CarVO.class);
		ResultBean result = new ResultBean();
		 try {
			  this.carService.updateCar(objMap);
			  result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
			 
		} catch (Exception e) {
			 log.error("查询车辆信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	
	
	 /**
	  * 删除车辆信息
	  * @param pb
	  * @return
	  */
	@RequestMapping(value="/deleteCar",method = RequestMethod.POST)
	public @ResponseBody ResultBean deleteCar(@RequestBody ParameterBean pb){
		CarVO objMap = (CarVO) pb.getParameter(CarVO.class);
		ResultBean result = new ResultBean();
		 try {
			 this.carService.deleteCar(objMap);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("删除车辆信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	
	/**
	 * 查询所有车辆信息
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/findAllCars",method = RequestMethod.POST)
	public @ResponseBody ResultBean findAllCars(@RequestBody ParameterBean pb){
		ResultBean result = new ResultBean();
		 try {
			 List<CarVO> vos = this.carService.findAllCars();
			 result.setResult(vos);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("查询车辆信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	/**
	 * 查询正在执行任务的车辆
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/findRunCars",method = RequestMethod.POST)
	public @ResponseBody ResultBean findRunCars(@RequestBody ParameterBean pb){
		ResultBean result = new ResultBean();
		 try {
			 List<RunCarVO> vos = this.carService.findRunCars();
			 result.setResult(vos);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("查询正在运行的车辆信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
    	
	

	
}
